package com.cn.hangyun.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cn.hangyun.common.DateUtil;
import com.cn.hangyun.dao.Rt_currentspeed_controlMapper;
import com.cn.hangyun.dao.Rt_currentspeed_dataMapper;
import com.cn.hangyun.dao.Rt_currentspeed_transducerMapper;
import com.cn.hangyun.dao.Rt_flow_controlMapper;
import com.cn.hangyun.dao.Rt_flow_dataMapper;
import com.cn.hangyun.dao.Rt_flow_transducerMapper;
import com.cn.hangyun.dao.Rt_waveheight_controlMapper;
import com.cn.hangyun.dao.Rt_waveheight_dataMapper;
import com.cn.hangyun.dao.Rt_waveheight_transducerMapper;
import com.cn.hangyun.model.Rt_currentspeed_control;
import com.cn.hangyun.model.Rt_currentspeed_transducer;
import com.cn.hangyun.model.Rt_flow_control;
import com.cn.hangyun.model.Rt_flow_transducer;
import com.cn.hangyun.model.Rt_waveheight_control;
import com.cn.hangyun.model.Rt_waveheight_transducer;
import com.cn.hangyun.model.requestVO.SingleTransducerRequestBean;
import com.cn.hangyun.service.IEnvironmentService;

@Service("environmentService")
public class EnvironmentServiceImpl implements IEnvironmentService {
	
	@Autowired
	private Rt_waveheight_transducerMapper waveTranMapper;
	
	@Autowired
	private Rt_waveheight_controlMapper waveContMapper;
	
	@Autowired
	private Rt_waveheight_dataMapper waveDataMapper;
	
	@Autowired
	private Rt_currentspeed_transducerMapper speedTranMapper;
	
	@Autowired
	private Rt_currentspeed_controlMapper speedContMapper;
	
	@Autowired
	private Rt_currentspeed_dataMapper speedDataMapper;
	
	@Autowired
	private Rt_flow_transducerMapper flowTranMapper;
	
	@Autowired
	private Rt_flow_controlMapper flowContMapper;
	
	@Autowired
	private Rt_flow_dataMapper flowDataMapper;
	


	@Override
	public List<Rt_waveheight_transducer> getAllWaveTran() {

		List<Rt_waveheight_transducer> list = waveTranMapper.selectAll();
		return list;
	}

	@Override
	public Rt_waveheight_control getLastWaveControl(Date current) {
		
		Rt_waveheight_control data = waveContMapper.selectLast(current);
		return data;
	}

	@Override
	public List<String> getWaveData(SingleTransducerRequestBean bean) {
		
		String controlId = bean.getControlId();
		Date start = bean.getStart();
		Date end = DateUtil.getEndTime(start, bean.getInterval());
		String tran = bean.getTran();
		
		List<String> list = waveDataMapper.selectData(controlId, start, end, tran);	
		return list;
	}
	
	@Override
	public List<Rt_currentspeed_transducer> getAllSpeedTran() {

		List<Rt_currentspeed_transducer> list = speedTranMapper.selectAll();
		return list;
	}

	@Override
	public Rt_currentspeed_control getLastSpeedControl(Date current) {
		
		Rt_currentspeed_control data = speedContMapper.selectLast(current);
		return data;
	}

	@Override
	public List<String> getSpeedData(SingleTransducerRequestBean bean) {
		
		String controlId = bean.getControlId();
		Date start = bean.getStart();
		Date end = DateUtil.getEndTime(start, bean.getInterval());
		String tran = bean.getTran();
		
		List<String> list = speedDataMapper.selectData(controlId, start, end, tran);	
		return list;
	}

	@Override
	public List<Rt_flow_transducer> getAllFlowTran() {

		List<Rt_flow_transducer> list = flowTranMapper.selectAll();
		return list;
	}

	@Override
	public Rt_flow_control getLastFlowControl(Date current) {
		
		Rt_flow_control data = flowContMapper.selectLast(current);
		return data;
	}

	@Override
	public List<String> getFlowData(SingleTransducerRequestBean bean) {

		String controlId = bean.getControlId();
		int inverval = bean.getInterval();
		Date start = bean.getStart();
		Date end = DateUtil.getEndTime(start, inverval);
		String trans = bean.getTran();
		List<String> list = flowDataMapper.selectData(
				controlId, start, end, trans);
		return list;
	}
	
	@Override
	public String getFlowAverage(SingleTransducerRequestBean bean) {
		
		String controlId = bean.getControlId();
		int inverval = bean.getInterval();
		Date start = bean.getStart();
		Date end = DateUtil.getEndTime(start, inverval);
		String trans = bean.getTran();
		
		String result = flowDataMapper.selectAverage(
				controlId, start, end, trans);
		return result;
	}

}
